package ch06;

import java.util.ArrayList;

public class Purse {
	
	private ArrayList<String> coins;
	
	public Purse()
	{
		coins = new ArrayList<String>();
	}
	
	public void addCoin(String coin)
	{
		if(coin.equals("Quater") || coin.equals("Dime") ||coin.equals("Nickel"))
		{
			coins.add(coin);
		}
	}
	
	public int getPurseSize()
	{
		return coins.size();
	}
	
	public String getCoin()
	{
		String coin = coins.get(0);
		coins.remove(0);
		return coin;
	}
	
	public String toString()
	{
		String returnValue = "Purse[";
		for(int i = 0; i < coins.size(); i ++)
		{
			if (i > 0)
			{
				returnValue += ", ";
			}
			returnValue += coins.get(i);
		}
		returnValue += "]";
		return returnValue;
	}
	
	public void reverse()
	{
		ArrayList<String> reversedCoins = new ArrayList<String>();
		for(int i = coins.size() - 1; i >= 0; i --)
		{
			reversedCoins.add(coins.get(i));
		}
		coins = reversedCoins;
	}
	
	public void transfer(Purse other)
	{
		while(other.getPurseSize() > 0)
		{
			this.addCoin(other.getCoin());
		}
	}
	
	public boolean sameContents(Purse other)
	{
		return this.toString().toLowerCase().equals(other.toString().toLowerCase());
	}

}
